<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>用户评论</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<link rel="stylesheet" href="../css/index.css" />
	 <link rel="stylesheet" href="../css/base.css">
	<script type="text/javascript" charset="utf-8" src="../js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
            $(document).ready(function(){
                $('.tijiao').click(function(){
                    var tContent =document.getElementById("tContent").value;
                    if(tContent==""){
                        return false;
                    }
                    else{
                        $('.text_content').innerText($('.box').val());
                    }})


            });
         //点击提交的方法
    function huoqu(){
        var tContent =document.getElementById("tContent").value;
        if(tContent.length==0){
            alert("评论内容不能为空。")

        }
        else{
         //1.得到输入的评论内容
        var xid='${sessionScope.xid}';
    	if(0<tContent.length<=50){
    	 var sid=document.getElementById("sid").value=xid;
    	//得到隐藏表单中的comid content（将comid和输入的评论内容传给后台）
    	var content=document.getElementById("content").value=tContent;
    	//将评论人也传过去
    	var name='${sessionScope.user.name}';
    	//如果评论人为空的话，提示先登录
    	if(name.length==0){
            alert("您还没登录呢");
            return ;
        }
    	var cname=document.getElementById("cname").value=name;
            var images='${sessionScope.user.avatar}';
            var image=document.getElementById("image").value=images;
    	 var form1=document.getElementById("form1");
    		 form1.submit();
        }else{
    	    alert("评论内容长度不得大于50个文字");
        }
        }
    }
    </script>
    <style type="text/css">
    #form1{
    	margin-top:2%;
    }
    </style>
  </head>
  <body>
    <a class="return-button" href="showAll">返回</a>
 	<span class="login_mesg">${sessionScope.user.name}</span><img class="user-img" src="${sessionScope.user.avatar}"/>
 	<hr/>
  <form action="insertComment" method="post" id="form1" >
   <input type="hidden" name="content" id="content"/>
   <input type="hidden" name="sid" id="sid"/>
   <input type="hidden" name="cname" id="cname"/>
    <input type="hidden" name="image" id="image"/>
	</form>
 <textarea name="" id="tContent" cols="30" rows="10" class="box"></textarea>
    <button class="tijiao" onclick="huoqu()">点击提交</button>
    <c:forEach items="${comm}" var="v" varStatus="status" begin="0" >
    <div class="hf_content">
        <div class="box-2">
            <span class="tx">
               <img src="${v.image}">
            </span>
            <div class="content">
            <!-- 这里查询的是登陆的那个人的信息 -->
                <div class="name">${v.cname}</div>
                <div class="time">${v.ctime}</div>&nbsp;&nbsp;&nbsp;&nbsp;
                <div>${fn:length(comm)-status.index}#</div>
            </div>

        </div>

        <div class="text_content">${v.ccontext}</div>
    </div>
 </c:forEach>
 </body>
</html>
